<template>
	<view class="body">
		<view class="input-box">
			<u-search placeholder="请输入姓名搜索" v-model="searchValue" @clear="clearSearch" @change="doSearch"
				:showAction="false" :actionStyle="actionStyle">
			</u-search>
		</view>
		<view class="ul-list1-xh">
			<view v-for="(item,index) in userList" :key="index" v-show="item.show">
				<view class="li">
					<view url="" hover-class="none" @click="setProject(item)">
						<view class="pic">
							<image src="https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/97280765e35649d5a8d40543540f91b7.png" style="width: 35rpx;" mode="widthFix"></image>
						</view>
						<view class="txt">
							<text>{{item.userName}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="notYetclass" v-if="notYet">
			<text class="notYetclass-text">抱歉，暂未找到</text>
		</view>

		<view class="" style="margin-bottom: -120rpx;">

		</view>
	</view>
</template>

<script>
	import uniPopup from '@/subPackTask/components/choose/uni-popup/uni-popup.vue';
	import { userList } from '@/api/user.js'
	export default {
		data() {
			return {
				actionStyle: {
					color: '#007AFF',
					fontWeight: 'bold',
				},
				searchValue: '',
				userList: [],
				notYet: false,
				callBackFunc: '',
			}
		},
		onLoad(option) {
			this.getList()
			this.type = option.type;
		},
		components: {
			uniPopup
		},
		methods: {
			//将数据返回上一页
			setProject(item) {
			    let pages = getCurrentPages();
			    let prevPage = pages[pages.length - 2]; //上一个页面
			    //直接调用上一个页面的setProject()方法，把数据存到上一个页面中去
			    prevPage.$vm.setProject({
			        id: item.userId,
			        name: item.userName,
					type:'负责人'
			    });
				uni.navigateBack();
			},
			doSearch() {
				if (this.searchValue === '') {
					this.clearSearch()
				}
				this.userList.map(e => {
					if (e.userName.indexOf(this.searchValue) > -1) {
						e.show = true
					} else {
						e.show = false
					}
				})
			},
			clearSearch() {
				this.searchValue = ''
				this.userList.map(e => e.show = true)
			},
			async getList() {
				const { data } = await userList();
				if (data.code == 200) {
					this.userList = data.data
					this.total = data.data.length
					this.userList.map(e => e.show = true)
				}
			},
		}
	}
</script>

<style>
	.body {
		padding-bottom: 180rpx;
	}

	.input-box {
		width: 700rpx;
		margin: 0 auto;
		padding: 10rpx 30rpx;
		padding-right: 30rpx;
		background-color: #ffffff;
	}
	
	.notYetclass {
		width: 750rpx;
		height: 700rpx;
	}

	.notYetclass-text {
		text-align: center;
		line-height: 700rpx;
		color: #008CFF;
	}
	
	.ul-list1-xh {
		overflow: hidden;
		padding: 20rpx 50rpx 0 30rpx;
	}
	
	.ul-list1-xh .li {
		padding: 20rpx 0;
		overflow: hidden;
		position: relative;
	}
	
	.ul-list1-xh .li .pic {
		float: left;
		margin-right: 20rpx;
	}
	
	.ul-list1-xh .li .txt {
		overflow: hidden;
		font-size: 30rpx;
		padding-bottom: 20rpx;
		border-bottom: 1px solid rgb(242, 242, 242);
	}
</style>